<template>
  <el-card class="common-container">
    <div style="margin-bottom: 20px; font-size: 20px;color: #606266;">商家列表</div>
    <div class="search-container">
      <el-input class="search-wrap" />
      <el-button type="primary" icon="search">查询</el-button>
      <el-button type="primary" icon="add" @click="handleAdd">添加模板</el-button>
    </div>

    <el-table :data="list" border>
      <el-table-column prop="title" label="商户名称" />
      <el-table-column prop="createTime" label="创建时间" />
      <el-table-column align="center" label="操作" width="250px">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="handleEdit(scope.row.id)">消息模板</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      style="margin-top: 10px "
      background
      :current-page.sync="pageNum"
      :page-size.sync="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script>
import { listTemplate } from '@/api/wxTemplateMsg'

export default {
  name: 'TemplateMsg',
  data() {
    return {
      pageNum: 0,
      pageSize: 10,
      list: [],
      total: 0
    }
  },
  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      listTemplate({ pageNum: this.pageNum, pageSize: this.pageSize }).then((res) => {
        this.list = res.data.list
        this.total = res.data.total
        return res
      })
    },
    handleAdd() {
      this.$router.push({ name: 'addTemplateMsg' })
    },
    handleSizeChange() {
    },
    handleCurrentChange() {
      this.getList()
    },
    handleEdit(id) {
      this.$router.push({ name: 'editTemplateMsg', params: { id: id } })
    },

    handleSend(id) {
      this.$router.push({ name: 'templateMsgSend', params: { id: id } })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .search-container {
    margin-top: 20px;
    margin-bottom: 20px
  }

  .search-wrap {
    width: 300px;
    margin-right: 10px
  }
</style>
